package com.dmgis.qxfw.dataservice.businessservice.nyfw.service.Impl;

import com.dmgis.qxfw.dataservice.businessservice.api.domain.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.ny.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.xt.users;
import com.dmgis.qxfw.dataservice.businessservice.common.domain.ResultObj;
import com.dmgis.qxfw.dataservice.businessservice.common.util.*;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.businessservice.nyfw.service.FarmXxHdService;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.sql.Timestamp;
import java.util.*;

/**
 * @ClassName FarmXxHdServiceImpl
 * @Description TODO
 * @Author sun
 * @Date 2021/7/27 13:16
 * @Version 1.0
 **/
@Service("FarmXxHdService")
public class FarmXxHdServiceImpl implements FarmXxHdService {
    ProcessRequestController pc = new ProcessRequestController();
    MongoService1 ms = new MongoService1();

    private  final String operatingSystem;

    @Autowired
    public FarmXxHdServiceImpl(String operatingSystem) {
        this.operatingSystem = operatingSystem;
    }

    /**
     * @Description: 查询所有协管员
     * @Author: sunshine
     * @Date: 2021/7/27 13:28
     **/
    @Override
    public Object bindCoordinateName() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Coordinator> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"coordinatename","stationid"});
            selectParam.put("method", "coordinator");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Coordinator>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 协管员上报信息管理-上报信息查看
     * @Author: sunshine
     * @Date: 2021/7/27 13:28
     **/
    @Override
    public List<CoordinatorInfo> getCrossingGuardView(String startDate, String endDate, String name) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CoordinatorInfo> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(startDate))
                builder.append(" and datereport >= '" + startDate + "'");
            if (!StringUtil.IsNullOrEmpty(endDate))
                builder.append(" and datereport <= '" + endDate + "'");
            if (!StringUtil.IsNullOrEmpty(name))
                builder.append(" and coordinateName = '" + name + "'");
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{"datereport desc"});
            selectParam.put("method", "coordinator_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CoordinatorInfo>>() {
            });
        } catch (Exception ex) {

        }
        return infoList;
    }

    /**
     * @Description: 协管员上报信息管理-删除上报信息
     * @Author: sunshine
     * @Date: 2021/7/27 14:40
     **/
    @Override
    public Object deleteCrossingGuard(String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "coordinator_info");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if ("-1".equals(message)) {
                return new ResultObj("删除失败!", "", false);
            }
            return new ResultObj("删除成功!", message, true);
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 协管员上报信息
     * @Author: sunshine
     * @Date: 2021/7/28 14:54
     **/
    @Override
    public Object AddCrossingGuard(CoordinatorInfo info, MultipartFile file, HttpServletRequest request) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<CoordinatorInfo> dataByInsert = new RequestDataByInsert<CoordinatorInfo>();
            List<CoordinatorInfo> coor = new ArrayList<>();
            coor.add(info);
            dataByInsert.setData(coor);
            insertParam.put("method", "coordinator_info");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                Map<String, String> selectParam = new HashMap<>();
                List<CoordinatorInfo> infoList = new ArrayList<>();
                StringBuilder builder = new StringBuilder();
                builder.append("1=1");
                if (info.getDatereport() != null)
                    builder.append(" and datereport = '" + info.getDatereport() + "'");
                if (!StringUtil.IsNullOrEmpty(info.getCoordinatename()))
                    builder.append(" and coordinatename = '" + info.getCoordinatename() + "'");
                selectRequest.setParam(builder.toString());
                selectParam.put("method", "coordinator_info");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message1 = pc.processRequest(selectParam);
                infoList = JsonUtil.jsonStr2TypeReference(message1, new TypeReference<List<CoordinatorInfo>>() {
                });
                if (infoList.size() > 0) {
                    String urlpath ;
                    if (operatingSystem.equals("Windows")){
                         urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\CrossingGuard\\";
                    }else {
                      urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/CrossingGuard/";
                    }

                    FileUtil.mkDirs(urlpath);
                    FileUtil.ClearTempFiles(urlpath, 100);
                    String fileName = infoList.get(0).getImgpath().trim();// 文件名
                    String localPath = urlpath + fileName;
                    File localFile = new File(localPath);
                    int returnTag = -1;
                    if (localFile.exists()) {
                        returnTag = -1;
                    }
                    byte[] bytes = file.getBytes();
                    String bytesString = new String(bytes, "ISO-8859-1");
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("id", infoList.get(0).getId());
                    map.put("table_name", "coordinator_info");
                    String type = file.getOriginalFilename().split("[.]")[file.getOriginalFilename().split("[.]").length - 1];
                    if (type.contains("doc"))
                        map.put("collectionName", "doc_file");
                    else if (type.contains("pdf"))
                        map.put("collectionName", "pdf_file");
                    else
                        map.put("collectionName", "image_file");
                    map.put("advCode", DbConfig.advCode);
                    map.put("data", bytesString.getBytes("ISO-8859-1"));
                    returnTag = ms.insertData(map);
                    file.transferTo(localFile);
                    if (returnTag != -1)
                        return new ResultObj("新增成功", returnTag, true);
                    else return new ResultObj("新增失败", "本地文件已存在，请更换文件", true);
                }
            }
            return new ResultObj("新增失败!", "-1", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 协理员上报回复-根据ID查看详细信息
     * @Author: sunshine
     * @Date: 2021/7/28 15:31
     **/
    @Override
    public Object getCrossingGuardByID(String id) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CoordinatorInfo> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"DateReport", "MessageReport"});
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(id))
                builder.append(" and id = '" + id + "'");
            selectRequest.setParam(builder.toString());
            selectParam.put("method", "coordinator_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CoordinatorInfo>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 协理员上报回复-回复消息（更新操作）
     * @Author: sunshine
     * @Date: 2021/7/28 15:36
     **/
    @Override
    public Object rervertCrossingGuard(CoordinatorInfo info) {
        Map<String, String> updateParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, CoordinatorInfo> dataByUpdate = new RequestDataByUpdate<String, CoordinatorInfo>();
            dataByUpdate.setParam("id='" + info.getId() + "'");
            dataByUpdate.setData(info);
            updateParam.put("method", "coordinator_info");
            updateParam.put("sqlType", "update");
            updateParam.put("advCode", DbConfig.advCode);
            updateParam.put("param", JsonUtil.object2Json(dataByUpdate));
            String message = pc.processRequest(updateParam);
            return new ResultObj("操作成功!", message, true);
        } catch (Exception ex) {
            return new ResultObj("操作失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 值班日志自动填充 姓名,单位
     * @Author: sunshine
     * @Date: 2021/7/29 10:21
     **/
    @Override
    public Object getInfocollectorbyName(String username) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Infocollector> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"name", "workplace"});
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(username))
                builder.append(" and infocollectorname = '" + username + "'");
            selectRequest.setParam(builder.toString());
            selectParam.put("method", "infocollector");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Infocollector>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /***
     * 值班日志添加
     * @param zbry
     * @param userType
     * @param userName
     * @return
     */
    @Override
    public Object insertDutylog(Dutylog zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<Dutylog> dataByInsert = new RequestDataByInsert<Dutylog>();
            List<Dutylog> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "dutylog");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            AddLog(userName, userType, "信息服务站：值班日志提交成功");
            if (!"-1".equals(message)) {
                return new ResultObj("新增成功!", message, true);
            }
            return new ResultObj("新增失败!", "", false);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 值班日志查询历史记录
     * @Author: sunshine
     * @Date: 2021/7/29 11:02
     **/
    @Override
    public Object getDutylog(users zbry, String startDate, String endDate, String id) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Dutylog> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append(" receivetime is not null");
            if (zbry != null && zbry.getType().equals("信息员") && !StringUtil.IsNullOrEmpty(zbry.getUsername())) {
                builder.append(" and principalname = '" + zbry.getUsername() + "'");
            }
            if (!StringUtil.IsNullOrEmpty(startDate))
                builder.append(" and receivetime >= '" + startDate + "'");
            if (!StringUtil.IsNullOrEmpty(endDate))
                builder.append(" and receivetime <= '" + endDate + "'");
            if (!StringUtil.IsNullOrEmpty(id))
                builder.append(" and id = '" + id + "'");
            selectRequest.setParam(builder.toString());
            selectParam.put("method", "dutylog");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Dutylog>>() {
            },"yyyy-MM-dd");
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 值班日志删除
     * @Author: sunshine
     * @Date: 2021/7/29 11:14
     **/
    @Override
    public Object deleteDutylog(users zbry, String startDate, String endDate, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "dutylog");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setColumns(new String[]{"id","principalname", "weainfoservicestation"});
                StringBuilder builder = new StringBuilder();
                builder.append(" receivetime is not null");
                if (zbry != null&&zbry.getType().equals("信息员") && !StringUtil.IsNullOrEmpty(zbry.getUsername()))
                    builder.append(" and principalname = '" + zbry.getUsername() + "'");
                if (!StringUtil.IsNullOrEmpty(startDate))
                    builder.append(" and receivetime >= '" + startDate + "'");
                if (!StringUtil.IsNullOrEmpty(endDate))
                    builder.append(" and receivetime <= '" + endDate + "'");
                selectRequest.setParam(builder.toString());
                selectParam.put("method", "dutylog");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Dutylog> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Dutylog>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：值班日志信息删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 值班日志更新
     * @Author: sunshine
     * @Date: 2021/7/29 11:24
     **/
    @Override
    public Object updateDutylog(Dutylog dutylog, users zbry, String startDate, String endDate, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Dutylog> dataByDelete = new RequestDataByUpdate<String, Dutylog>();
            dataByDelete.setParam("id = '" + id + "'");
            dataByDelete.setData(dutylog);
            selectParam.put("method", "dutylog");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setColumns(new String[]{"id","principalname", "weainfoservicestation"});
                StringBuilder builder = new StringBuilder();
                builder.append(" receivetime is not null");
                if (zbry!=null&&zbry.getType().equals("信息员") && !StringUtil.IsNullOrEmpty(zbry.getUsername()))
                    builder.append(" and principalname = '" + zbry.getUsername() + "'");
                if (!StringUtil.IsNullOrEmpty(startDate))
                    builder.append(" and receivetime >= '" + startDate + "'");
                if (!StringUtil.IsNullOrEmpty(endDate))
                    builder.append(" and receivetime <= '" + endDate + "'");
                if (!StringUtil.IsNullOrEmpty(id))
                    builder.append(" and id = '" + id + "'");
                selectRequest.setParam(builder.toString());
                selectParam.put("method", "dutylog");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Dutylog> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Dutylog>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：值班日志信息更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 添加信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:12
     **/
    @Override
    public Object insertInfor(Infocollector zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            String stationname = zbry.getStationid();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            Map<String, String> selectParam = new HashMap<>();
            List<StationInfo> infoList = new ArrayList<>();
                selectRequest.setColumns(new String[]{"stationid"});
                StringBuilder builder = new StringBuilder();
                builder.append("1=1");
                if (!StringUtil.IsNullOrEmpty(stationname))
                    builder.append(" and stationname like '%" + stationname + "%'");
                selectRequest.setParam(builder.toString());
                selectParam.put("method", "station_info");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message1 = pc.processRequest(selectParam);
                infoList = JsonUtil.jsonStr2TypeReference(message1, new TypeReference<List<StationInfo>>() {
                });
                if (infoList != null) {
                    zbry.setStationid(infoList.get(0).getStationid());
                }
            RequestDataByInsert<Infocollector> dataByInsert = new RequestDataByInsert<Infocollector>();
            List<Infocollector> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "infocollector");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            AddLog(userName, userType, "信息服务站：信息员信息添加成功");
            return new ResultObj("新增成功!", message, true);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据用户账号查询信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:21
     **/
    @Override
    public List<Infocollector> getInfor(String username) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Infocollector> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(username))
                builder.append(" and infocollectorname  like '%" + username + "%'");
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{"id desc"});
            selectParam.put("method", "infocollector");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Infocollector>>() {
            });
            for (Infocollector info : infoList) {
                info.setInfocollectorpwd(info.getInfocollectorpwd().trim());
            }
        } catch (Exception ex) {

        }
        return infoList;
    }

    @Override
    public List<users> getUser(String username) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<users> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(username))
                builder.append(" and username  like '%" + username + "%'");
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{"id desc"});
            selectParam.put("method", "users");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<users>>() {
            });
        } catch (Exception ex) {
        }
        return infoList;
    }

    /**
     * @Description: 删除信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:21
     **/
    @Override
    public Object deleteInfor(users zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "infocollector");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setSort(new String[]{"id desc"});
                selectParam.put("method", "infocollector");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Infocollector> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Infocollector>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：信息员信息删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 更新信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:21
     **/
    @Override
    public Object updateInfor(Infocollector infor, users user, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Infocollector> dataByDelete = new RequestDataByUpdate<String, Infocollector>();
            dataByDelete.setParam("id = '" + id + "'");
            dataByDelete.setData(infor);
            selectParam.put("method", "infocollector");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectRequest.setSort(new String[]{"id desc"});
                selectRequest.setParam("id = '" + id + "'");
                selectParam.put("method", "infocollector");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Infocollector> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Infocollector>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：信息员信息更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }


    /**
     * @Description: 添加协管员
     * @Author: sunshine
     * @Date: 2021/7/29 14:12
     **/
    @Override
    public Object insertCrossingGuard(Coordinator zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
            //根据站点名获取站点id
            String stationname = zbry.getStationid();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            Map<String, String> selectParam = new HashMap<>();
            List<StationInfo> infoList = new ArrayList<>();
            try {
                selectRequest.setColumns(new String[]{"stationid"});
                StringBuilder builder = new StringBuilder();
                builder.append("1=1");
                if (!StringUtil.IsNullOrEmpty(stationname))
                    builder.append(" and stationname like '%" + stationname + "%'");
                selectRequest.setParam(builder.toString());
                selectParam.put("method", "station_info");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message1 = pc.processRequest(selectParam);
                infoList = JsonUtil.jsonStr2TypeReference(message1, new TypeReference<List<StationInfo>>() {
                });
             if (infoList != null) {
                 zbry.setStationid(infoList.get(0).getStationid());
             }
            RequestDataByInsert<Coordinator> dataByInsert = new RequestDataByInsert<Coordinator>();
            List<Coordinator> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "coordinator");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userName, userType, "信息服务站：协管员信息添加成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * @Description: 根据用户账号查询信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:21
     **/
    @Override
    public List<Coordinator> getCrossingGuard(String username) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Coordinator> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(username))
                builder.append(" and coordinatename like '%" + username + "%'");
            selectRequest.setParam(builder.toString());
            selectParam.put("method", "coordinator");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Coordinator>>() {
            });
            for (Coordinator coordinator : infoList) {
                coordinator.setCoordinatepwd(coordinator.getCoordinatepwd().trim());
            }
        } catch (Exception ex) {
        }
        return infoList;
    }

    /**
     * @Description: 删除信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:21
     **/
    @Override
    public Object deleteCrossingGuard(users zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "coordinator");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "coordinator");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Coordinator> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Coordinator>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：协管员信息删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 更新信息员
     * @Author: sunshine
     * @Date: 2021/7/29 14:21
     **/
    @Override
    public Object updateCrossingGuard(Coordinator infor, users user, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Coordinator> dataByDelete = new RequestDataByUpdate<String, Coordinator>();
            dataByDelete.setParam("id = '" + id + "'");
            dataByDelete.setData(infor);
            selectParam.put("method", "coordinator");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "coordinator");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Coordinator> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Coordinator>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：协管员信息更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据站点名称查询作展示
     * @Author: sunshine
     * @Date: 2021/7/29 15:04
     **/
    @Override
    public Object getNFStaInfo(String staName, HttpServletRequest request) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<StationInfo> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"stationid", "stationname", "stationtype", "county", "township", "village", "city", "lon", "lat", "alti", "forecaststationjoin", "forecaststationid", "smallscalestationjoin", "smallscalestationid", "basicsituation", "pic", "maincrop", "maincroprepweaserproducts", "maincropanni", "farmmonitorelement", "farminfopubway"});
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(staName))
                builder.append(" and stationname like'%" + staName + "%'");
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{"stationid desc"});
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<StationInfo>>() {
            });
            if (infoList.size() != 0) {
                for (StationInfo info : infoList) {
                    if (info.getPic().trim() != "") {
                        String servicePath = "";// 服务器文件

                        String urlpath ;
                        if (operatingSystem.equals("Windows")){
                            urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\StationPic\\";// 临时文件目录
                        }else {
                           urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp/StationPic/";// 临时文件目录
                        }

                        FileUtil.mkDirs(urlpath);// 创建文件夹，生成多级目录
                        FileUtil.ClearTempFiles(urlpath, 1000);// 清除缓存
                        String fileName = info.getPic().trim();// 文件名
                        String jpgPath = urlpath + fileName;
                        File jpgFile = new File(jpgPath);
                        if (jpgFile.exists()) {
                            if (operatingSystem.equals("Windows")){
                                servicePath = "Temp\\StationPic\\" + fileName;
                            }else {
                                servicePath = "Temp/StationPic/" + fileName;
                            }

                            String path = request.getContextPath();
                            info.setPic(DbConfig.IP + path + "/" + servicePath.replace("\\", "/"));
                        } else {
                            Map<String, Object> map = new HashMap<String, Object>();
                            map.put("stationid", info.getStationid());
                            map.put("table_name", "station_info");
                            map.put("collectionName", "image_file");
                            map.put("advCode", DbConfig.advCode);
                            byte[] data = ms.selectData(map);
                            if (data == null) {
                                info.setPic("");
                            } else {
                                FileUtil.bytesToFile(data, jpgPath);
                                String path = request.getContextPath();
                                info.setPic(DbConfig.IP + path + "/" + servicePath.replace("\\", "/"));
                            }
                        }
                    }
                    String strtext = "预报站点编号:" + info.getForecaststationid() + " 所属乡镇:" + info.getTownship() + " 主要农作物:" + info.getMaincrop() + " 基本情况:" + info.getBasicsituation();
                    info.setBasicsituation(strtext);
                }
            }
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 获取农作物
     * @Author: sunshine
     * @Date: 2021/7/29 15:14
     **/
    @Override
    public Object getCrops() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CropGrowdateIndexlib> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"distinct(rtrim(ltrim(cropname))) as cropname"});
            selectParam.put("method", "crop_growdate_indexlib");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateIndexlib>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 新增农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 15:25
     **/
    @Override
    public StationInfo addNFSta(StationInfo zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<StationInfo> dataByInsert = new RequestDataByInsert<StationInfo>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            Map<String, String> selectParam = new HashMap<>();
            List<StationInfo> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "station_info");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userType,userName,"后台管理:新增链接成功");
                selectRequest.setParam("stationid = '" + zbry.getStationid() + "'");
                selectParam.put("method", "station_info");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String linkMessage = pc.processRequest(selectParam);
                List<StationInfo> stationInfos = JsonUtil.jsonStr2TypeReference(linkMessage, new TypeReference<List<StationInfo>>() {
                });
                return stationInfos.get(0);
            }
        } catch (Exception ex) {

        }
        return null;
    }


    /**
     * @Description: 更新农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 16:42
     **/
    @Override
    public Object updateNFSta(users user, StationInfo zbry,String stationid) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, StationInfo> dataByDelete = new RequestDataByUpdate<String, StationInfo>();
            dataByDelete.setParam("stationid = '" + stationid + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "信息服务站：农服站点信息更新成功");
                return Integer.parseInt(message);
            }
        } catch (Exception ex) {
        }
        return null;
    }

    /**
     * @Description: 删除农服站点
     * @Author: sunshine
     * @Date: 2021/7/29 16:45
     **/
    @Override
    public Object deleteNFStaInfo(users zbry, String stationid) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("stationid = '" + stationid + "'");
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：农服站点信息删除成功");
                return Integer.parseInt(message);
            }
        } catch (Exception ex) {
        }
        return null;
    }

    /**
     * @Description: 根据作物品种做展示 - 发育期指标
     * @Author: sunshine
     * @Date: 2021/7/30 9:06
     **/
    @Override
    public Object getMatuIndex(String staName, HttpServletRequest request) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CropGrowdateIndexlib> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(staName))
                builder.append(" and cropname like'%" + staName + "%'");
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{"indexid desc"});
            selectParam.put("method", "crop_growdate_indexlib");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateIndexlib>>() {
            });
            for (CropGrowdateIndexlib cropGrowdateIndexlib : infoList) {
                cropGrowdateIndexlib.setCropname(cropGrowdateIndexlib.getCropname().trim());
            }
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 得到作物类别和名称
     * @Author: sunshine
     * @Date: 2021/7/30 9:15
     **/
    @Override
    public Object getCropTypeAndName() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CropGrowdateIndexlib> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"distinct type", "cropname"});
            selectParam.put("method", "crop_growdate_indexlib");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateIndexlib>>() {
            });
            for (CropGrowdateIndexlib cropGrowdateIndexlib : infoList) {
                cropGrowdateIndexlib.setCropname(cropGrowdateIndexlib.getCropname().trim());
            }
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 得到发育期和作物名称
     * @Author: sunshine
     * @Date: 2021/7/30 9:17
     **/
    @Override
    public Object getCropGrowdateAndName() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CropGrowdateIndexlib> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"distinct growdatename", "cropname"});
            selectParam.put("method", "crop_growdate_indexlib");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateIndexlib>>() {
            });
            for (CropGrowdateIndexlib cropGrowdateIndexlib : infoList) {
                cropGrowdateIndexlib.setCropname(cropGrowdateIndexlib.getCropname().trim());
            }
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 新增生育期指标
     * @Author: sunshine
     * @Date: 2021/7/30 9:23
     **/
    @Override
    public Object addMatuIndex(CropGrowdateIndexlib zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<CropGrowdateIndexlib> dataByInsert = new RequestDataByInsert<CropGrowdateIndexlib>();
            List<CropGrowdateIndexlib> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "crop_growdate_indexlib");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userName, userType, "信息服务站：生育期指标添加成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * @Description: 根据indexid修改updateMatuIndex
     * @Author: sunshine
     * @Date: 2021/7/30 9:25
     **/
    @Override
    public Object updateMatuIndex(users user, CropGrowdateIndexlib zbry) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, CropGrowdateIndexlib> dataByDelete = new RequestDataByUpdate<String, CropGrowdateIndexlib>();
            dataByDelete.setParam("indexid = '" + zbry.getIndexid() + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "crop_growdate_indexlib");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "crop_growdate_indexlib");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropGrowdateIndexlib> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateIndexlib>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：生育期指标更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据indexid删除发育期指标
     * @Author: sunshine
     * @Date: 2021/7/30 9:28
     **/
    @Override
    public Object deleteMatuIndex(users zbry, String indexid) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("indexid = '" + indexid + "'");
            selectParam.put("method", "crop_growdate_indexlib");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "crop_growdate_indexlib");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropGrowdateIndexlib> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateIndexlib>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：生育期指标删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物品种做展示 - 病虫害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:32
     **/
    @Override
    public Object getDisIndex(String staName) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Diseaseindexlib> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(staName)) {
                builder.append(" and cropname like'%" + staName + "%'");
            }
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{"id desc"});
            selectParam.put("method", "diseaseindexlib");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Diseaseindexlib>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 新增病虫害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:35
     **/
    @Override
    public Object addDisIndex(Diseaseindexlib zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<Diseaseindexlib> dataByInsert = new RequestDataByInsert<Diseaseindexlib>();
            List<Diseaseindexlib> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "diseaseindexlib");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            AddLog(userName, userType, "信息服务站：病虫害指标添加成功");
            return new ResultObj("新增成功!", message, true);
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id修改updateDisIndex  病虫害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:43
     **/
    @Override
    public Object updateDisIndex(users user, Diseaseindexlib zbry, String indexid) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Diseaseindexlib> dataByDelete = new RequestDataByUpdate<String, Diseaseindexlib>();
            dataByDelete.setParam("id = '" + indexid + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "diseaseindexlib");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "diseaseindexlib");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<Diseaseindexlib> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Diseaseindexlib>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：病虫害指标更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id删除deleteDisIndex  病虫害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:46
     **/
    @Override
    public Object deleteDisIndex(users zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "diseaseindexlib");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "diseaseindexlib");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropGrowdateIndexlib> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateIndexlib>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：病虫害指标删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示  气象灾害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:48
     **/
    @Override
    public Object getMeteoroDisIndex(String staName) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CropWeatherDistIndexlib> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(staName))
                builder.append(" and cropname like'%" + staName + "%'");
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{"id desc"});
            selectParam.put("method", "crop_weather_dist_indexlib");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropWeatherDistIndexlib>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 得到农作物易发灾害类型和名称
     * @Author: sunshine
     * @Date: 2021/7/30 10:50
     **/
    @Override
    public Object getEasyhappentypeAndName() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CropWeatherDistIndexlib> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"distinct easyhappentype", "cropname"});
            selectParam.put("method", "crop_weather_dist_indexlib");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropWeatherDistIndexlib>>() {
            });
            for (CropWeatherDistIndexlib cropWeatherDistIndexlib : infoList) {
                cropWeatherDistIndexlib.setCropname(cropWeatherDistIndexlib.getCropname().trim());
            }
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 新增气象灾害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:53
     **/
    @Override
    public Object addMeteoDisIndex(CropWeatherDistIndexlib zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<CropWeatherDistIndexlib> dataByInsert = new RequestDataByInsert<CropWeatherDistIndexlib>();
            List<CropWeatherDistIndexlib> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "crop_weather_dist_indexlib");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userName, userType, "信息服务站：气象灾害指标添加成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * @Description: 根据id修改气象灾害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:56
     **/
    @Override
    public Object updateMeteoDisIndex(users user, CropWeatherDistIndexlib zbry) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, CropWeatherDistIndexlib> dataByDelete = new RequestDataByUpdate<String, CropWeatherDistIndexlib>();
            dataByDelete.setParam("id = '" + zbry.getId() + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "crop_weather_dist_indexlib");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "crop_weather_dist_indexlib");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropWeatherDistIndexlib> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropWeatherDistIndexlib>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：气象灾害指标更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id删除气象灾害指标
     * @Author: sunshine
     * @Date: 2021/7/30 10:58
     **/
    @Override
    public Object deleteMeteoDisIndex(users zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "crop_weather_dist_indexlib");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "crop_weather_dist_indexlib");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropWeatherDistIndexlib> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropWeatherDistIndexlib>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：病虫害指标删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示 历史发育期资料
     * @Author: sunshine
     * @Date: 2021/7/30 11:01
     **/
    @Override
    public Object getHistoryMatuInfo(String staName) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<CropGrowdateHistory> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(staName))
                builder.append(" and cropname like'%" + staName + "%'");
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{"id desc"});
            selectParam.put("method", "crop_growdate_history");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateHistory>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 新增历史发育期资料
     * @Author: sunshine
     * @Date: 2021/7/30 11:03
     **/
    @Override
    public Object addHistoryMatuInfo(CropGrowdateHistory zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<CropGrowdateHistory> dataByInsert = new RequestDataByInsert<CropGrowdateHistory>();
            List<CropGrowdateHistory> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "crop_growdate_history");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userName, userType, "信息服务站：历史发育期资料添加成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * @Description: 根据id修改历史发育期资料updateHistoryMatuInfo
     * @Author: sunshine
     * @Date: 2021/7/30 11:05
     **/
    @Override
    public Object updateHistoryMatuInfo(users user, CropGrowdateHistory zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, CropGrowdateHistory> dataByDelete = new RequestDataByUpdate<String, CropGrowdateHistory>();
            dataByDelete.setParam("id = '" + id + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "crop_growdate_history");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "crop_growdate_history");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropGrowdateHistory> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateHistory>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：历史发育期资料更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /***
     * 根据id删除历史发育期资料deleteHistoryMatuInfo
     * @param zbry
     * @param id
     * @return
     */
    @Override
    public Object deleteHistoryMatuInfo(users zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "crop_growdate_history");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "crop_growdate_history");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropGrowdateHistory> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropGrowdateHistory>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：历史发育期资料删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示历史产量资料
     * @Author: sunshine
     * @Date: 2021/7/30 11:12
     **/
    @Override
    public Object getHistoryYieldsInfo(String staName) {
        return GetDataByType("cropyield_history", staName, "id desc");
    }

    /**
     * @Description: 新增历史产量资料
     * @Author: sunshine
     * @Date: 2021/7/30 12:25
     **/
    @Override
    public Object addHistoryYieldsInfo(CropyieldHistory zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<CropyieldHistory> dataByInsert = new RequestDataByInsert<CropyieldHistory>();
            List<CropyieldHistory> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "cropyield_history");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userName, userType, "信息服务站：历史产量资料添加成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * @Description: 根据id修改历史产量资料
     * @Author: sunshine
     * @Date: 2021/7/30 12:27
     **/
    @Override
    public Object updateHistoryYieldsInfo(users user, CropyieldHistory zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, CropyieldHistory> dataByDelete = new RequestDataByUpdate<String, CropyieldHistory>();
            dataByDelete.setParam("id = '" + id + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "cropyield_history");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "cropyield_history");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropyieldHistory> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropyieldHistory>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：历史产量资料更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id删除历史产量资料
     * @Author: sunshine
     * @Date: 2021/7/30 12:28
     **/
    @Override
    public Object deleteHistoryYieldsInfo(users zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "cropyield_history");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "cropyield_history");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<CropyieldHistory> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropyieldHistory>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：历史产量资料删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示历史病虫害资料
     * @Author: sunshine
     * @Date: 2021/7/30 12:50
     **/
    @Override
    public Object getHistoryDisInfo(String staName) {
        return GetDataByType("diseasedatalib", staName, "stationid desc");
    }

    /**
     * @Description: 得到病虫害名称和作物名称
     * @Author: sunshine
     * @Date: 2021/7/30 12:55
     **/
    @Override
    public Object getDiseasesnameAndName() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<Diseasedatalib> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"distinct diseasesname", "cropname"});
            selectParam.put("method", "diseasedatalib");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Diseasedatalib>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 获取站点信息
     * @Author: sunshine
     * @Date: 2021/7/30 13:06
     **/
    @Override
    public Object getNfStationID() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<StationInfo> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"stationid"});
            selectRequest.setSort(new String[]{"stationid"});
            selectParam.put("method", "station_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<StationInfo>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 新增历史病虫害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:08
     **/
    @Override
    public Object addHistoryDisInfo(Diseasedatalib zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        String message = "";
        try {
            RequestDataByInsert<Diseasedatalib> dataByInsert = new RequestDataByInsert<Diseasedatalib>();
            List<Diseasedatalib> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "diseasedatalib");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userName, userType, "信息服务站：历史病虫害资料添加成功");
            }
        } catch (Exception ex) {
            //TODO
        }
        return message;
    }

    /**
     * @Description: 根据stationid修改历史病虫害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:12
     **/
    @Override
    public Object updateHistoryDisInfo(users user, Diseasedatalib zbry, String stationid) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, Diseasedatalib> dataByDelete = new RequestDataByUpdate<String, Diseasedatalib>();
            dataByDelete.setParam("stationid = '" + stationid + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "diseasedatalib");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(user.getUsername(), user.getType(), "信息服务站：历史病虫害资料更新成功");
                return new ResultObj("更新成功!", message, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据stationid删除历史病虫害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:13
     **/
    @Override
    public Object deleteHistoryDisInfo(users zbry, String stationid) {
        Map<String, String> selectParam = new HashMap<>();
        String message = "";
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("stationid = '" + stationid + "'");
            selectParam.put("method", "diseasedatalib");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：历史产量资料删除成功");
            }
        } catch (Exception ex) {
            //TODO
        }
        return message;
    }

    /**
     * @Description: 根据作物名做展示历史气象灾害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:18
     **/
    @Override
    public Object getHistoryMeteoDisInfo(String staName) {
        return GetDataByType("agri_weather_dist_record", staName, "cropname");
    }

    /**
     * @Description: 历史气象灾害资料 - 灾害种类
     * @Author: sunshine
     * @Date: 2021/7/30 13:22
     **/
    @Override
    public Object getDisastertype() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<AgriWeatherDistRecord> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"distinct disastertype"});
            selectParam.put("method", "agri_weather_dist_record");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriWeatherDistRecord>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 新增历史气象灾害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:26
     **/
    @Override
    public Object addHistoryMeteoDisInfo(AgriWeatherDistRecord zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<AgriWeatherDistRecord> dataByInsert = new RequestDataByInsert<AgriWeatherDistRecord>();
            List<AgriWeatherDistRecord> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "agri_weather_dist_record");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userName, userType, "信息服务站：历史气象灾害资料添加成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * @Description: 根据id修改历史气象灾害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:29
     **/
    @Override
    public Object updateHistoryMeteoDisInfo(users user, AgriWeatherDistRecord zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, AgriWeatherDistRecord> dataByDelete = new RequestDataByUpdate<String, AgriWeatherDistRecord>();
            dataByDelete.setParam("id = '" + id + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "agri_weather_dist_record");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "agri_weather_dist_record");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<AgriWeatherDistRecord> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriWeatherDistRecord>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：历史气象灾害资料更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据id删除历史气象灾害资料
     * @Author: sunshine
     * @Date: 2021/7/30 13:33
     **/
    @Override
    public Object deleteHistoryMeteoDisInfo(users zbry, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "agri_weather_dist_record");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "agri_weather_dist_record");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<AgriWeatherDistRecord> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriWeatherDistRecord>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：历史气象灾害资料删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据作物名做展示农事活动指标
     * @Author: sunshine
     * @Date: 2021/7/30 13:35
     **/
    @Override
    public Object getNSServiceIndexInfo(String staName) {
        return GetDataByType("agri_service_index", staName, "indexname");
    }

    /**
     * @Description: 指数名称
     * @Author: sunshine
     * @Date: 2021/7/30 13:37
     **/
    @Override
    public Object getIndexname() {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<AgriServiceIndex> infoList = new ArrayList<>();
        try {
            selectRequest.setColumns(new String[]{"distinct indexname"});
            selectParam.put("method", "agri_service_index");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriServiceIndex>>() {
            });
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
        return new ResultObj("查询成功!", infoList, true);
    }

    /**
     * @Description: 新增农事活动指标
     * @Author: sunshine
     * @Date: 2021/7/30 13:39
     **/
    @Override
    public Object addNSSrvIndex(AgriServiceIndex zbry, String userType, String userName) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<AgriServiceIndex> dataByInsert = new RequestDataByInsert<AgriServiceIndex>();
            List<AgriServiceIndex> coor = new ArrayList<>();
            coor.add(zbry);
            dataByInsert.setData(coor);
            insertParam.put("method", "agri_service_index");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                AddLog(userName, userType, "信息服务站：农事活动指标添加成功");
                return new ResultObj("新增成功!", message, true);
            }
        } catch (Exception ex) {
            return new ResultObj("新增失败!", ex.getMessage(), false);
        }
        return new ResultObj("新增失败!", "", false);
    }

    /**
     * @Description: 根据indexid修改农事活动指标
     * @Author: sunshine
     * @Date: 2021/7/30 13:41
     **/
    @Override
    public Object updateNSSrvIndex(users user, AgriServiceIndex zbry, String indexid) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, AgriServiceIndex> dataByDelete = new RequestDataByUpdate<String, AgriServiceIndex>();
            dataByDelete.setParam("id = '" + indexid + "'");
            dataByDelete.setData(zbry);
            selectParam.put("method", "agri_service_index");
            selectParam.put("sqlType", "update");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "agri_service_index");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<AgriServiceIndex> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriServiceIndex>>() {
                });
                AddLog(user.getUsername(), user.getType(), "信息服务站：农事活动指标更新成功");
                return new ResultObj("更新成功!", infoList, true);
            } else {
                return new ResultObj("更新失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("更新失败!", ex.getMessage(), false);
        }
    }

    /**
     * @Description: 根据indexid删除农事活动指标
     * @Author: sunshine
     * @Date: 2021/7/30 13:42
     **/
    @Override
    public Object deleteNSSrvIndex(users zbry, String indexid) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + indexid + "'");
            selectParam.put("method", "agri_service_index");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            int i = Integer.parseInt(message);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "agri_service_index");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<AgriServiceIndex> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriServiceIndex>>() {
                });
                AddLog(zbry.getUsername(), zbry.getType(), "信息服务站：农事活动指标删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }


    /**
     * @Description: 添加日志记录
     * @Author: sunshine
     * @Date: 2021/7/29 10:47
     **/
    public void AddLog(String userName, String userType, String log) {
        Map<String, String> insertParam = new HashMap<>();
        try {
            RequestDataByInsert<Log> dataByInsert = new RequestDataByInsert<Log>();
            List<Log> coor = new ArrayList<>();
            Log log1 = new Log();
            log1.setUsername(userName);
            log1.setStime(Timestamp.valueOf(DateTime.now().toDateTimeString()));
            log1.setThing(log);
            log1.setSystype(Integer.parseInt(userType));
            coor.add(log1);
            dataByInsert.setData(coor);
            insertParam.put("method", "log");
            insertParam.put("sqlType", "insert");
            insertParam.put("advCode", DbConfig.advCode);
            insertParam.put("param", JsonUtil.object2Json(dataByInsert));
            String message = pc.processRequest(insertParam);
        } catch (Exception ex) {
            ex.getStackTrace();
        }
    }

    /**
     * @Description: 得到数据  农业初次展示
     * bdName 数据库表
     * staName 条件
     * sort 排序字段
     * @Author: sunshine
     * @Date: 2021/7/30 11:15
     **/
    public Object GetDataByType(String bdName, String staName, String sort) {
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        Map<String, String> selectParam = new HashMap<>();
        List<?> infoList = new ArrayList<>();
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("1=1");
            if (!StringUtil.IsNullOrEmpty(staName) && "agri_service_index".equals(bdName)) {
                builder.append(" and indexname like'%" + staName + "%'");
            }else if (!StringUtil.IsNullOrEmpty(staName))
                builder.append(" and cropname like'%" + staName + "%'");
            selectRequest.setParam(builder.toString());
            selectRequest.setSort(new String[]{sort});
            selectParam.put("method", bdName);
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            switch (bdName) {
                case "cropyield_history":
                    infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<CropyieldHistory>>() {
                    });
                    break;
                case "diseasedatalib":
                    infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<Diseasedatalib>>() {
                    });
                    break;
                case "agri_weather_dist_record":
                    infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriWeatherDistRecord>>() {
                    });
                    break;
                case "agri_service_index":
                    infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriServiceIndex>>() {
                    });
                    break;
            }
            return new ResultObj("查询成功!", infoList, true);
        } catch (Exception ex) {
            return new ResultObj("查询失败!", ex.getMessage(), false);
        }
    }


    @Override
    public Object rervertShangBao(InfocollectorInfo info) {
        Map<String, String> updateParam = new HashMap<>();
        try {
            RequestDataByUpdate<String, InfocollectorInfo> dataByUpdate = new RequestDataByUpdate<String, InfocollectorInfo>();
            dataByUpdate.setParam("id='" + info.getId() + "'");
            dataByUpdate.setData(info);
            updateParam.put("method", "infocollector_info");
            updateParam.put("sqlType", "update");
            updateParam.put("advCode", DbConfig.advCode);
            updateParam.put("param", JsonUtil.object2Json(dataByUpdate));
            String message = pc.processRequest(updateParam);
            return new ResultObj("操作成功!", message, true);
        } catch (Exception ex) {
            return new ResultObj("操作失败!", ex.getMessage(), false);
        }
    }

    @Override
    public Object deleteShangBaoById(users user, String id) {
        Map<String, String> selectParam = new HashMap<>();
        try {
            RequestDataByDelete dataByDelete = new RequestDataByDelete();
            dataByDelete.setParam("id = '" + id + "'");
            selectParam.put("method", "infocollector_info");
            selectParam.put("sqlType", "delete");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(dataByDelete));
            String message = pc.processRequest(selectParam);
            if (!StringUtil.IsNullOrEmpty(message) && Integer.parseInt(message) > 0) {
                RequestDataBySelect selectRequest = new RequestDataBySelect();
                selectParam = new HashMap<>();
                selectParam.put("method", "infocollector_info");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                message = pc.processRequest(selectParam);
                List<AgriServiceIndex> infoList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<AgriServiceIndex>>() {
                });
                AddLog(user.getUsername(), user.getType(), "互动信息：上报删除成功");
                return new ResultObj("删除成功!", infoList, true);
            } else {
                return new ResultObj("删除失败!", "请联系管理员", false);
            }
        } catch (Exception ex) {
            return new ResultObj("删除失败!", ex.getMessage(), false);
        }
    }
}